<?php

class memberController extends RPHP_Controller
{

    //权限前缀
    protected $_pvprefix = "member";



    public function memberlist()
    {
        $priv  = array($this->_pvprefix . "_ls");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $para = array();
            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }

            if (!empty($_GET['keyword'])) {
                $para['keyword'] = addslashes(stripslashes(trim($_GET['keyword'])));
            }

            if ($_GET['member_level'] != "") {
                $para['member_level'] = intval($_GET['member_level']);
            }

            if ($_GET['agent_level'] != "") {
                $para['agent_level'] = intval($_GET['agent_level']);
            }

            if ($_GET['maker_level'] != "") {
                $para['maker_level'] = intval($_GET['maker_level']);
            }

            if ($_GET['pid'] != "") {
                $para['pid'] = intval($_GET['pid']);
            }

            if ($_GET['stat'] != "") {
                $para['stat'] = intval($_GET['stat']);
            }

            $this->view->data = $model->getMemberList($para, $page);

            //编辑
            $this->view->pv['edit'] = $model->checkPriv($this->_pvprefix . "_ed", false, false);
            //充值
            $this->view->pv['recharge'] = $model->checkPriv($this->_pvprefix . "_rc", false, false);

            //获取页码
            if ($this->view->data['maxpage'] > 1) {
                $this->view->data['spage'] = $model->fun->spage($this->view->data['page'], $this->view->data['maxpage']);
            }

            $this->view->auth = $auth;
            $this->display();

        }

    }

    //导出订单csv
    public function export_csv()
    {
        $priv = array($this->_pvprefix . "_ls");

        $model = $this->model;
        $auth = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            if (!empty($_GET['keyword'])) {
                $para['keyword'] = addslashes(stripslashes(trim($_GET['keyword'])));
            }

            if ($_GET['member_level'] != "") {
                $para['member_level'] = intval($_GET['member_level']);
            }

            if ($_GET['agent_level'] != "") {
                $para['agent_level'] = intval($_GET['agent_level']);
            }

            if ($_GET['maker_level'] != "") {
                $para['maker_level'] = intval($_GET['maker_level']);
            }

            if ($_GET['pid'] != "") {
                $para['pid'] = intval($_GET['pid']);
            }

            if ($_GET['stat'] != "") {
                $para['stat'] = intval($_GET['stat']);
            }

            $model->exportMemberListCSV($para);
        }

    }

    //导出订单
    public function export()
    {
        $priv = array($this->_pvprefix . "_ls");

        $model = $this->model;
        $auth = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            if (!empty($_GET['keyword'])) {
                $para['keyword'] = addslashes(stripslashes(trim($_GET['keyword'])));
            }

            if ($_GET['member_level'] != "") {
                $para['member_level'] = intval($_GET['member_level']);
            }

            if ($_GET['pid'] != "") {
                $para['pid'] = intval($_GET['pid']);
            }

            if ($_GET['stat'] != "") {
                $para['stat'] = intval($_GET['stat']);
            }
            $data = $model->getExportMemberList($para);

            if ($data['data']) {
                $orderData = array();

                foreach ($data['data'] as $v) {

                    $orderData[] = array(
                        'uid' => $v['uid'],
                        'recode' => $v['recode'],
                        'mobile' => $v['mobile'],
                        'realname' => $v['realname'],
                        'name' => $v['name'],
                        'pname' => $v['pid'] > 0 && $data['parents'][$v['pid']] ? $data['parents'][$v['pid']]['realname'] : '--',
                        'precode' => $v['pid'] > 0 && $data['parents'][$v['pid']] ? $data['parents'][$v['pid']]['recode'] : '--',
                        'pcount' => $data['child'][$v['uid']] > 0 ? $data['child'][$v['uid']] : 0,
                        'create_time' => date("Y-m-d H:i", $v['create_time']),
                        'member_level' => $this->c['member_level_t'][$v['member_level']],
                        'agent_level' => $this->c['honor_level_t'][$v['agent_level']],
                        'money' => $data['balance'][$v['uid']]['money'],
                        'revenue' => $data['balance'][$v['uid']]['revenue'],
                        'gold_money' => $data['balance'][$v['uid']]['gold_money'],
                        'ximi_money' => $data['balance'][$v['uid']]['ximi_money'],
                        'coupon' => $data['balance'][$v['uid']]['coupon'],
                        'ticket' => $data['balance'][$v['uid']]['ticket'],
                        'stat' => $this->c['stat']['normal_t'][$v['stat']],
                        'bind_time' => $v['bind_time']>0?date("Y-m-d H:i",$v['bind_time']):"",
                    );
                }

                //print_r($orderData);die;

                if ($orderData) {
                    RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                    $excel = new PHPExcel();

                    //设置excel属性基本信息
                    $excel->getProperties()->setCreator("LEHUO")
                        ->setLastModifiedBy("LEHUO")
                        ->setTitle("LEHUO")
                        ->setSubject("用户列表")
                        ->setDescription("")
                        ->setKeywords("用户列表")
                        ->setCategory("");
                    $excel->setActiveSheetIndex(0);
                    $excel->getActiveSheet()->setTitle("用户列表");
                    //填入表头主标题
                    $excel->getActiveSheet()->setCellValue('A1', '用户列表');
                    //填入表头副标题
                    $excel->getActiveSheet()->setCellValue('A2', '导出时间：' . date("Y-m-d H:i:s", time()));
                    //合并表头单元格
                    $excel->getActiveSheet()->mergeCells('A1:M1');
                    $excel->getActiveSheet()->mergeCells('A2:M2');

                    //设置表头行高
                    $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
                    $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
                    $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

                    //设置表头字体
                    $excel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
                    $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
                    $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
                    $excel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
                    $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
                    $excel->getActiveSheet()->getStyle('A3:M3')->getFont()->setBold(true);
                    $letter = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R','S'); //,'N'   快递费用
                    $tableheader = array('UID', '邀请码', '手机号码', '会员昵称', '姓名', '推荐人', '推荐人邀请码', ' TA的推荐', ' 注册时间', ' 会员级别', '荣誉级别', '硒豆', '可提现', '金花', '硒米', '代金券', '商品票', '状态','绑定手机时间');
                    $excel_H = 4;
                    for ($i = 0; $i < count($tableheader); $i++) {
                        $excel->getActiveSheet()->setCellValue("$letter[$i]3", "$tableheader[$i]");
                    }

                    $excel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                    $excel->getActiveSheet()->getStyle('M')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

                    $excel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
                    $excel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
                    $excel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
                    $excel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
                    $excel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('L')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('N')->setWidth(20);
                    $excel->getActiveSheet()->getColumnDimension('S')->setWidth(30);

                    foreach ($orderData as $num => $v) {
                        $line = $num + $excel_H;
                        $excel->getActiveSheet()->getRowDimension($line)->setRowHeight(24);
                        $excel->getActiveSheet()->setCellValue('A' . $line, $v['uid']);
                        $excel->getActiveSheet()->setCellValue('B' . $line, ' ' . $v['recode'] . " ");
                        $excel->getActiveSheet()->setCellValue('C' . $line, $v['mobile'] . " ");
                        $excel->getActiveSheet()->setCellValue('D' . $line, $v['realname'] . " ");
                        $excel->getActiveSheet()->setCellValue('E' . $line, $v['name']);
                        $excel->getActiveSheet()->setCellValue('F' . $line, $v['pname'] . ' ');
                        $excel->getActiveSheet()->setCellValue('G' . $line, $v['precode']);
                        $excel->getActiveSheet()->setCellValue('H' . $line, $v['pcount']);
                        $excel->getActiveSheet()->setCellValue('I' . $line, $v['create_time']);
                        $excel->getActiveSheet()->setCellValue('J' . $line, $v['member_level']);
                        $excel->getActiveSheet()->setCellValue('K' . $line, $v['agent_level']);
                        $excel->getActiveSheet()->setCellValue('L' . $line, $v['money']);
                        $excel->getActiveSheet()->setCellValue('M' . $line, $v['revenue']);
                        $excel->getActiveSheet()->setCellValue('N' . $line, $v['gold_money'] . " ");
                        $excel->getActiveSheet()->setCellValue('O' . $line, $v['ximi_money']);
                        $excel->getActiveSheet()->setCellValue('P' . $line, $v['coupon']);
                        $excel->getActiveSheet()->setCellValue('Q' . $line, $v['ticket']);
                        $excel->getActiveSheet()->setCellValue('R' . $line, $v['stat']);
                        $excel->getActiveSheet()->setCellValue('S' . $line, $v['bind_time']);
                        $excel->getActiveSheet()->getStyle('A' . $line . ':M' . $line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    }


                    //设置单元格边框
                    $styleArray = array(
                        'borders' => array(
                            'allborders' => array(
                                //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                                'style' => PHPExcel_Style_Border::BORDER_THIN, //细边框
                                //'color' => array('argb' => 'FFFF0000'),
                            ),
                        ),
                    );
                    //设置单元格边框
                    $excel->getActiveSheet()->getStyle('A1:M2')->applyFromArray($styleArray);
                    //垂直居中
                    $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    //水平居中
                    $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                    //创建Excel输入对象
                    $write = new PHPExcel_Writer_Excel5($excel);
                    header("Pragma: public");
                    header("Expires: 0");
                    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                    header("Content-Type:application/force-download");
                    header("Content-Type:application/vnd.ms-execl");
                    header("Content-Type:application/octet-stream");
                    header("Content-Type:application/download");
                    header('Content-Disposition:attachment;filename=用户信息'.date('Y-m-d H:i',time()).'.xls');
                    header("Content-Transfer-Encoding:binary");
                    $write->save('php://output');
                } else {
                    header("Content-type: text/html; charset=utf-8");
                    echo "没有要导出的数据";
                    die;
                }

            }

        }

    }
    // 查看详细资料
    public function detail()
    {
        $priv = array($this->_pvprefix . "_vw");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $uid = intval($_GET['uid']);
            if ($uid > 0) {
                $data  = $model->getDetailUser($uid);
                $datas = $model->getSingleUser($uid);
                if ($data) {

                    $this->view->auth = $auth;
                    $this->view->data = $data;

                    $this->display();
                }

            }

            if (!$data) {
                $this->redirect("/member/memberlist");
            }

        }

    }

    //编辑会员
    public function edit()
    {
        $priv = array($this->_pvprefix . "_ed");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $uid = intval($_GET['uid']);
            if ($uid > 0) {
                $data = $model->getSingleUser($uid);
            }

            if ($data) {
                
                $this->view->data = $data;
                $this->view->auth = $auth;
                $this->display();
            }

        }

    }

    //AJAX操作
    public function ajax()
    {
        $priv = array($this->_pvprefix . "_vw");

        $model        = $this->model;
        $auth         = $model->checkPriv($priv);
        $data['code'] = 900;
        if ($auth) {
            if ($_POST['act'] == 'searchuser') {
                $data = $model->searchWeixinUser($_POST['kw']);
            }
            // 搜索会员
            elseif ($_GET['act'] == 'search') {
                $data = $model->getSearchMember($_GET['keyword']);
            } elseif ($_POST['act'] == 'getchild') {
                $user = $model->getChild(intval($_POST['uid']));
                if ($user) {
                    $data['code'] = 200;
                    $data['user'] = $user;
                } else {
                    $data['code'] = 404;
                }

            } elseif ($_POST['act'] == 'ajax_member') {
                $all_member = $model->getAllMember($_POST);
                if ($all_member) {
                    $data['code']       = 200;
                    $data['all_member'] = $all_member;
                }
            } elseif ($_POST['act'] == 'seek') {
                if ($_POST['start_time'] != "") {
                    $start_time = strtotime($_POST['start_time']);
                    if ($start_time > 0) {
                        $para['start_time'] = $start_time;
                    }
                }
                if ($_POST['end_time'] != "") {
                    $end_time = strtotime($_POST['end_time']);
                    if ($end_time > 0) {
                        $para['end_time'] = $end_time;
                    }

                }
                $data = $model->getSeek($para);
            }

        }
        echo json_encode($data);

    }

    //保存会员数据
    public function savemember()
    {
        $priv = array($this->_pvprefix . "_ls");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->code = 900;

            if ($_POST['act'] == "edit" && $model->checkPriv($this->_pvprefix . "_ed", false, false)) {
                $this->view->success = "编辑会员成功";
                $this->view->link    = array(
                    array('name' => '继续编辑会员', 'url' => '/member/edit?uid=' . $_POST['uid']),
                    array('name' => '返回来源页面', 'url' => $_POST['ref']),
                    array('name' => '返回会员列表', 'url' => '/member/memberlist'),
                );
                $this->view->code = $model->saveMember($_POST, $_POST['uid']);

            } elseif ($_POST['act'] == "delete" && $model->checkPriv($this->_pvprefix . "_de", false, false)) {

                $this->view->success = "删除会员成功";
                $this->view->link    = array(
                    array('name' => '返回会员列表', 'url' => '/member/memberlist'),
                );
                $this->view->code = $model->deleteMember($_POST['uid']);

            } elseif ($_POST['act'] == "recharge" && $model->checkPriv($this->_pvprefix . "_rc", false, false)) {

                $this->view->success = "充值成功";
                $this->view->link    = array(
                    array('name' => '返回来源页面', 'url' => $_POST['ref']),
                    array('name' => '返回会员列表', 'url' => '/member/memberlist'),
                );
                $this->view->code = $model->saveRecharge($_POST);

            }

            $this->displaydo();

        }
    }

    //会员收藏商品列表
    public function collection()
    {
        $priv  = array($this->_pvprefix . "_co");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);

        $this->view->auth = $auth;

        if (isset($_GET['uid']) && $_GET['uid'] != "") {
            $uid         = intval($_GET['uid']);
            $para['uid'] = $uid;
        }
        if (isset($_GET['goods_id']) && $_GET['goods_id'] != "") {
            $goods_id         = intval($_GET['goods_id']);
            $para['goods_id'] = $goods_id;
        }

        if (intval($_GET['page']) > 0) {
            $page = intval($_GET['page']);
        } else {
            $page = 1;
        }

        $this->view->data = $model->getCollection($para, $page);

        //获取页码
        if ($this->view->data['maxpage'] > 1) {
            $this->view->data['spage'] = $model->fun->spage($this->view->data['page'], $this->view->data['maxpage']);
        }

        $this->display();
    }

    //会员足迹商品列表
    public function history()
    {
        $priv  = array($this->_pvprefix . "_hi");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);

        $this->view->auth = $auth;

        if (isset($_GET['uid']) && $_GET['uid'] != "") {
            $uid         = intval($_GET['uid']);
            $para['uid'] = $uid;
        }
        if (isset($_GET['goods_id']) && $_GET['goods_id'] != "") {
            $goods_id         = intval($_GET['goods_id']);
            $para['goods_id'] = $goods_id;
        }

        if (intval($_GET['page']) > 0) {
            $page = intval($_GET['page']);
        } else {
            $page = 1;
        }

        $this->view->data = $model->gethistory($para, $page);
        //获取页码
        if ($this->view->data['maxpage'] > 1) {
            $this->view->data['spage'] = $model->fun->spage($this->view->data['page'], $this->view->data['maxpage']);
        }

        //编辑权限
        $this->view->pv['edit'] = $model->checkPriv($this->_pvprefix . "_ed", false);
        //删除权限
        $this->view->pv['del'] = $model->checkPriv($this->_pvprefix . "_de", false);
        $this->display();
    }

    //会员搜索
    public function search()
    {
        $priv  = array($this->_pvprefix . "_sech");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            $this->view->auth = $auth;
            $this->display();
        }
    }

    //会员充值
    public function recharge()
    {
        $priv = array($this->_pvprefix . "_rc");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $uid = intval($_GET['uid']);
            if ($uid > 0) {
                $data = $model->getSingleUser($uid);
            }

            if ($data) {

                $this->view->auth = $auth;
                $this->view->data = $data;

                $this->display();

            } else {
                RPHP_RR::nodata();
            }

        }

    }
    //订单导出
    public function exportBatch()
    {
        $priv = array($this->_pvprefix . "_ex");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            $data = $model->getMemberData($start_time, $end_time, $warehouse_type, $type);

            if ($data['data']) {

                foreach ($data['data'] as $k => $v) {
                    $orderData[] = array(
                        'uid'          => $v['uid'],
                        'recode'       => $v['recode'],
                        'mobile'       => $v['mobile'],
                        'realname'     => $v['realname'],
                        'name'         => $v['name'],
                        'pid'          => "[" . $v['pid'] . "]" . $data['parents'][$v['pid']]['realname'],
                        'pid_num'      => $data['child'][$v['uid']] > 0 ? $data['child'][$v['uid']] . "人" : "0人",
                        'create_time'  => $v['create_time'],
                        'member_level' => $v['member_level'],
                        'agent_level'  => $v['agent_level'],
                        'amount'       => $data['amount'][$v['uid']] > 0 ? $data['amount'][$v['uid']] : 0,
                        'money'        => $data['balance'][$v['uid']]['money'],
                        'jifen'        => $data['balance'][$v['uid']]['jifen'],
                        'revenue'      => $data['balance'][$v['uid']]['revenue'],
                        'stat'         => $v['stat'],

                    );
                }
            }

            // echo "<pre>";
            // print_r($orderData);die();

            if ($orderData) {
                RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                $excel = new PHPExcel();

                //设置excel属性基本信息
                $excel->getProperties()->setCreator("LEHUO")
                    ->setLastModifiedBy("LEHUO")
                    ->setTitle("LEHUO")
                    ->setSubject("会员信息列表")
                    ->setDescription("")
                    ->setKeywords("会员信息列表")
                    ->setCategory("");
                $excel->setActiveSheetIndex(0);
                $excel->getActiveSheet()->setTitle("会员信息列表");
                //填入表头主标题
                $excel->getActiveSheet()->setCellValue('A1', '会员信息列表');
                //填入表头副标题
                // $excel->getActiveSheet()->setCellValue('A2', '导出时间范围：' . date("Y-m-d H:i:s", $start_time) . '至' . date("Y-m-d H:i:s", $end_time));
                //合并表头单元格
                $excel->getActiveSheet()->mergeCells('A1:P1');
                $excel->getActiveSheet()->mergeCells('A2:P2');

                //设置表头行高
                $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
                $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
                $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

                //设置表头字体
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
                $excel->getActiveSheet()->getStyle('A3:P3')->getFont()->setBold(true);
                $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P');
                $tableheader = array('UID', '邀请码', '手机号码', '会员昵称', '姓名', '推荐人', '推荐人邀请码', 'TA的推荐', '注册时间', 'VIP分销级别', '代理级别', '积分', '累计消费', '可用肽币', '可提现肽币', '状态');
                $excel_H     = 4;
                for ($i = 0; $i < count($tableheader); $i++) {
                    $excel->getActiveSheet()->setCellValue("$letter[$i]3", "$tableheader[$i]");
                }

                $excel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('M')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

                $excel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('L')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('N')->setWidth(20);
                foreach ($orderData as $num => $v) {
                    $line = $num + $excel_H;
                    $excel->getActiveSheet()->getRowDimension($line)->setRowHeight(24);
                    $excel->getActiveSheet()->setCellValue('A' . $line, $v['uid']);
                    $excel->getActiveSheet()->setCellValue('B' . $line, $v['recode']);
                    $excel->getActiveSheet()->setCellValue('C' . $line, $v['mobile'] . " ");
                    $excel->getActiveSheet()->setCellValue('D' . $line, $v['realname']);
                    $excel->getActiveSheet()->setCellValue('E' . $line, $v['name']);
                    $excel->getActiveSheet()->setCellValue('F' . $line, $v['pid']);
                    $excel->getActiveSheet()->setCellValue('G' . $line, $v['store']);
                    $excel->getActiveSheet()->setCellValue('H' . $line, $v['pid_num']);
                    $excel->getActiveSheet()->setCellValue('I' . $line, $v['create_time']);
                    $excel->getActiveSheet()->setCellValue('J' . $line, $v['member_level']);
                    $excel->getActiveSheet()->setCellValue('K' . $line, $v['agent_level']);
                    $excel->getActiveSheet()->setCellValue('L' . $line, $v['jifen']);
                    $excel->getActiveSheet()->setCellValue('M' . $line, $v['amount']);
                    $excel->getActiveSheet()->setCellValue('N' . $line, $v['money']);
                    $excel->getActiveSheet()->setCellValue('O' . $line, $v['revenue']);
                    $excel->getActiveSheet()->setCellValue('P' . $line, $v['stat']);

                    $excel->getActiveSheet()->getStyle('A' . $line . ':M' . $line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

                }

                //设置单元格边框
                $styleArray = array(
                    'borders' => array(
                        'allborders' => array(
                            //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                            'style' => PHPExcel_Style_Border::BORDER_THIN, //细边框
                            //'color' => array('argb' => 'FFFF0000'),
                        ),
                    ),
                );
                //设置单元格边框
                $excel->getActiveSheet()->getStyle('A1:O2')->applyFromArray($styleArray);
                //垂直居中
                $excel->getActiveSheet()->getStyle('A1:O2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                //水平居中
                $excel->getActiveSheet()->getStyle('A1:O2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                //创建Excel输入对象
                $write = new PHPExcel_Writer_Excel5($excel);
                header("Pragma: public");
                header("Expires: 0");
                header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                header("Content-Type:application/force-download");
                header("Content-Type:application/vnd.ms-execl");
                header("Content-Type:application/octet-stream");
                header("Content-Type:application/download");
                header('Content-Disposition:attachment;filename="会员信息列表' . date("Y-m-d_H:i:s", $_SERVER['REQUEST_TIME']) . '.xls"');
                header("Content-Transfer-Encoding:binary");
                $write->save('php://output');
            } else {
                header("Content-type: text/html; charset=utf-8");
                echo "没有要导出的数据";die;
            }
            // }

        }
    }

}
